<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>大事件-后台登录页</title>
  <link rel="stylesheet" href="js/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="css/reset.css">
  <link rel="stylesheet" type="text/css" href="css/iconfont.css">
  <link rel="stylesheet" type="text/css" href="css/main.css">
</head>

<body>
<div class="main_wrap">
  <div class="header">
    <a href="#" class="logo">
      <img src="images/logo.png" alt="">
    </a>
    <div class="copyright">CopyRight © 2019 深圳百秀信息技术股份有限公司
      <br>
      All Rights Reserved
    </div>
  </div>

  <div class="login_form_con">
    <div class="login_title"></div>
    <form class="login_form">
      <i class="iconfont icon-user"></i>
      <i class="iconfont icon-key"></i>
      <input type="text" class="input_txt" placeholder="邮箱/手机号" name="username" value="admin" value2="李思思">
      <input type="password" class="input_pass" placeholder="密码" name="password" value="123456">
      <input type="button" class="input_sub" value="登 录">
    </form>
  </div>

</div>
<script src="js/jquery-1.12.4.min.js"></script>
<script src="js/bootstrap/js/bootstrap.min.js"></script>
<script !src="">
  $(function () {
    function showModel(msg) {
      return confirm(msg)
    }

    let $inputTxt = $('.input_txt');
    let $inputPass = $('.input_pass');
    $('body').on({
      click: function (e) {
        // 动态委派
        console.log('click', '.input_sub');
        let username = $inputTxt.val();
        let password = $inputPass.val();
        if (!username || username.trim().length === 0) {
          showModel('账号不能为空');
          $inputTxt.focus();
          return;
        }
        if (!password || password.trim().length === 0) {
          showModel('密码不能为空');
          $inputPass.focus();
          return;
        }
        obj = {
          'username': username,
          'password': password
        };
        // let serialize = $('form').serialize();
        console.log(obj)
        $.ajax({
          url: 'http://localhost:8080/admin/user/login',
          method: 'post',
          dataType: 'json',
          data: obj,
          // data: formData,
          success: function (data) {
            console.log('ajax结果', data);
            if (data.code === 200) {
              showModel('登入成功 ');
              location.assign('./index.html');
              // location.href='./index.html';

            } else {
              showModel(data.msg);
              $inputTxt.focus();
            }
          }
        })
      }
    }, '.input_sub');
  })
</script>
</body>

</html>